//
//  ZDSearchViewController.m
//  1012GiftTips
//
//  Created by Apple on 15/10/15.
//  Copyright © 2015年 itcast. All rights reserved.
//

#import "ZDSearchViewController.h"
#import "ZDSearchBar.h"

@interface ZDSearchViewController ()

@property (nonatomic, strong) ZDSearchBar *searchBar;

@end

@implementation ZDSearchViewController

- (instancetype)init
{
    return [self initWithStyle:UITableViewStyleGrouped];
}

- (instancetype)initWithStyle:(UITableViewStyle)style
{
    return [super initWithStyle:UITableViewStyleGrouped];
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.navigationItem.titleView = self.searchBar;
    
    //隐藏返回按钮
    self.navigationItem.hidesBackButton = YES;
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStyleDone target:self action:@selector(cancel)];
    
    [self.searchBar becomeFirstResponder];
}


- (void)cancel
{
//    [self.view endEditing:YES];
    
    [self.searchBar resignFirstResponder];
    
    [self.navigationController popViewControllerAnimated:YES];
}


#pragma mark 懒加载
- (ZDSearchBar *)searchBar
{
    if (!_searchBar)
    {
        _searchBar = [ZDSearchBar searchBar];
    }
    
    return _searchBar;
}


@end
